package com.example.yqand4v1_1.controller;

import com.example.yqand4v1_1.beans.Result;
import com.example.yqand4v1_1.dto.AddNewsDiscussDTO;
import com.example.yqand4v1_1.service.NewsDiscussService;
import com.example.yqand4v1_1.vo.NewsDiscussVO;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/newsDiscuss")
public class NewsDiscussController {

    @Resource
    private NewsDiscussService newsDiscussService;

    // 新闻评论
    @PostMapping(value = "/add")
    public Result<Void> add(@RequestBody AddNewsDiscussDTO data) {
        newsDiscussService.addNewsDiscuss(data);
        return Result.success();
    }

    // 获取新闻评论列表
    @GetMapping(value = "/list/{newsId}")
    public Result<List<NewsDiscussVO>> getByNewsId(@PathVariable("newsId") int newsId) {
        return Result.success(newsDiscussService.getByNewsId(newsId));
    }
}
